home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
program
/
fpk65_66.zip
/
SOURCE
/
RTL
/
DOS
/
HEX.PP
< prev
next >
Wrap
Text File
|
1996-07-02
|
746b
|
39 lines
unit Hex;
interface
function HexStr(val:LongInt;cnt:Byte):string;
function BinStr(val:Word;cnt:Byte):string;
implementation
function HexStr(val:LongInt;cnt:Byte):string;
const hexval:string[16]=('0123456789ABCDEF');
var s:string[20];
l2,i:integer;
l1:longInt;
begin
s[0]:=char(cnt);
L1:=longint($F) shl (4*(cnt-1));
for i:=1 to cnt do begin
L2:=(Val and L1) shr (4*(cnt-i));
L1:=L1 shr 4;
s[i]:=hexval[L2+1];
end;
HexStr:=s;
end;
function BinStr(val:Word;cnt:Byte):string;
var s:string[16];
mask,i:word;
begin
s[0]:=char(cnt);
mask:=word(1) shl (cnt-1);
for i:=1 to cnt do begin
if (val and mask)<>0 then s[i]:='1' else s[i]:='0';
mask:=mask shr 1;
end;
BinStr:=s;
end;
end.